# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.dwd.dwd_warhouse.dwd_wide_unsign_summary_waybill_dt import jms_dwd__dwd_wide_unsign_summary_waybill_dt
# from jms.dwd.oms.dwd_oms_order_dt import jms_dwd__dwd_oms_order_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
# from jms.dm.route.dm_route_selected import dm__dm_route_whole_selected
from jms.dim.tab.dim_tab_platform_effect_config_base import jms_dim__dim_tab_platform_effect_config_base
from jms.dwd.oms.dwd_oms_waybill_dt import jms_dwd__dwd_oms_waybill_dt
from jms.dwd.tab.dwd_tab_barscan_deliver_base_dt import jms_dwd__dwd_tab_barscan_deliver_base_dt
from jms.dim.dim_lmdm_sys_special_time_limit_base import jms_dim__dim_lmdm_sys_special_time_limit_base
from jms.dim.dim_lmdm_sys_second_code import jms_dim__dim_lmdm_sys_second_code
from jms.dim.dim_lmdm_sys_first_code import jms_dim__dim_lmdm_sys_first_code
from jms.dwd.dwd_terminal_sign_all_detail_new_dt import jms_dwd__dwd_terminal_sign_all_detail_new_dt
from jms.dm.prescription.dm_prescription_reach_pre_details_dt import jms_dm__dm_prescription_reach_pre_details_dt

jms_dm__dm_prescription_reach_details_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_prescription_reach_details_dt',
    email=['zhangqinglin@jtexpress.com','yl_bigdata@yl-scm.com'],
    conn_id='spark_route',
    name='jms_dm__dm_prescription_reach_details_dt_{{ execution_date | date_add(1) | cst_ds }}',
    # sla=timedelta(hours=7),
    driver_memory='10G',
    executor_memory='22G',
    executor_cores=6,
    num_executors=84,
    pool_slots=8,
    conf={'spark.dynamicAllocation.enabled': 'false',  # 动态资源开启
          'spark.shuffle.service.enabled': 'false',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.sql.shuffle.partitions': 1000 ,
          'spark.shuffle.file.buffer': '64',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=6'
          },
    # jars='hdfs:///user/spark/work/dm/hejian/dm__dm_waybill_prescription_reach_details/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    jars='hdfs:///scheduler/jms/spark/zql/prescription_new/common-1.0-SNAPSHOT.jar',
    # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.prescription.PrescriptionReachDetails',  # spark 主类
    # application='hdfs:///user/spark/work/dm/hejian/dm__dm_waybill_prescription_reach_details/original-jobs-1.0-SNAPSHOT.jar',  # spark jar 包
    application='hdfs:///scheduler/jms/spark/zql/prescription_new/original-jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds }}'],
    execution_timeout=timedelta(hours=1),
)

jms_dm__dm_prescription_reach_details_dt << [
    jms_dwd__dwd_wide_unsign_summary_waybill_dt,
    jms_dwd__dwd_oms_waybill_dt,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_tab_platform_effect_config_base,
    jms_dwd__dwd_tab_barscan_deliver_base_dt,
    jms_dim__dim_lmdm_sys_special_time_limit_base,
    jms_dim__dim_lmdm_sys_second_code,
    jms_dim__dim_lmdm_sys_first_code,
    jms_dwd__dwd_terminal_sign_all_detail_new_dt,
    jms_dm__dm_prescription_reach_pre_details_dt
]
